package com.zhuimeng.Application.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhuimeng.Application.dao.RechargeOrderDao;
import com.zhuimeng.Application.entity.RechargeOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RechangeOrderService implements IRechangeOrderService {

    @Resource
    private RechargeOrderDao rechargeOrderDao;

    @Override
    public int insertOrder(RechargeOrder rechargeOrder) {
        return rechargeOrderDao.insert(rechargeOrder);
    }

    @Override
    public List<RechargeOrder> queryRechangeORderByUid(Integer uid) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id", uid);
        queryWrapper.orderByDesc("create_time");
        return rechargeOrderDao.selectList(queryWrapper);
    }

    @Override
    public int updateOrderStatus(String orderId, Integer status) {
        RechargeOrder rechargeOrder = rechargeOrderDao.selectById(orderId);
        rechargeOrder.setStatus(status);

        return rechargeOrderDao.updateById(rechargeOrder);
    }

    @Override
    public RechargeOrder getByOrderId(String orderId) {
        return rechargeOrderDao.selectById(orderId);
    }

    @Override
    public int alipayOrder(String orderId) {
        return 0;
    }
}
